package com.banzhi.shop.entity.CollegeShouyi;


import com.banzhi.shop.MyApp;
import com.banzhi.shop.state.URLString;
import com.banzhi.shop.utils.LoadingDialogUtils;
import com.banzhi.shop.utils.LogUtils;
import com.banzhi.shop.utils.ToastUtils;
import com.google.gson.Gson;

import org.json.JSONException;
import org.json.JSONObject;
import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

/**
 * Created by Administrator on 2018/5/11.
 */

public class CollegeShouyiImpl implements ICollegeShouyiModel {
    @Override
    public void getData(int page,String status,final CollegeShouyiCallBack callBack) {
        RequestParams params = new RequestParams(URLString.CollegeShouyiURL);
        params.addBodyParameter("memberId", MyApp.loginMessage.getString("id", ""));
        params.addBodyParameter("page", page + "");
        params.addBodyParameter("status", status);
        LogUtils.d("CollegeShouyiImpl", params.toString());
        x.http().post(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                LogUtils.d("CollegeShouyiImpl66666", result.toString());
                try {
                    JSONObject jsonobject = new JSONObject(result);
                    if (jsonobject.optString("code").equals("0")) {
                        Gson gson = new Gson();
                        CollegeShouyiData collegeShouyiData = gson.fromJson(result, CollegeShouyiData.class);
                  if (collegeShouyiData.getData().getList()!= null) {
                            callBack.ongetDataSuccess(collegeShouyiData.getData().getList());
                  }
                    } else {
                        callBack.ongetDataError(jsonobject);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                LogUtils.e("CollegeShouyiURL", "---onError----" + ex.toString());
                 LoadingDialogUtils.dismiss();
                ToastUtils.makeToastShort("网络加载失败,请稍后再试(89)");
            }

            @Override
            public void onCancelled(CancelledException cex) {
            }

            @Override
            public void onFinished() {
                LoadingDialogUtils.dismiss();
            }
        });

    }
}
